<template>
  <div>
    <c-table-box ref="cTableBox" :off-set="-20" hide-func checkbox :other-raw="paramsRaw" :other-filters="otherFilters" :table-config="tableConfig" @selection-change="selectionChange">
      <template #btn>
        <template v-if="type==='waitConfirm'">
          <Confirm :sel-data="selections" @on-success="refreshTableData" />
        </template>
      </template>
    </c-table-box>
  </div>
</template>
<script>
import { otherFiltersItem } from '@/utils'
import Confirm from './confirm'
export default {
  name: 'List',
  components: {
    Confirm
  },
  props: {
    type: {
      type: String,
      default: ''
    },
    serachFilters: {
      type: Array,
      default: () => []
    },
    activeType: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      exportVisible: false,
      tableConfig: {
        interfacePath: '/slm-admin/api/v1/shopDecoration/pageSelect',
        hideFuncBar: true,
        sort: 'createTime',
        order: 'desc',
        apiHeader: {
          'Permission-perCode': 'appointconfirm',
          'Permission-App': 'slm'
        },
        setting: [
          {
            prop: 'constCode',
            label: '门店建设项目号',
            width: 180
          },
          {
            prop: 'decorationTaskCode',
            label: '装修任务号',
            width: 200,
            className: 'btn-green',
            isButton: true,
            clickFun: this.toDetail
          },
          {
            prop: 'nature',
            label: '装修性质',
            width: 120,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'DECORATION_NATURE'
            }
          },
          {
            prop: 'shopName',
            label: '所属门店',
            width: 120
          },
          {
            prop: 'clientName',
            label: '所属客户',
            width: 120
          },
          {
            prop: 'officeName',
            label: '所属办事处',
            width: 120
          },
          {
            prop: 'range',
            label: '装修范围',
            width: 120,
            render: (h, r) => {
              return h('c-dict-range-view', { props: { dictTypeCode: 'DECORATION_RANGE', value: r.range }})
            }
          },
          {
            prop: 'schedule',
            label: '装修进度',
            width: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'DECORATION_SCHEDULE'
            }
          },
          {
            prop: 'steps',
            label: '装修步骤',
            width: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'SHOP_DECORATION_STEPS'
            }
          },
          {
            prop: 'state',
            label: '装修状态',
            width: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'SHOP_DECORATION_STATE'
            }
          },
          {
            prop: 'isApplyReportOutTime',
            label: '装修申请是否超期',
            width: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'isOutTimeUnaccept',
            label: '验收申请是否超期',
            width: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'constUnitName',
            label: '施工单位',
            width: 120
          },
          {
            prop: 'principal',
            label: '施工负责人',
            width: 120
          },
          {
            prop: 'proSupervisorName',
            label: '工程监理',
            width: 120
          },
          {
            prop: 'marketType',
            label: '报图类型',
            width: 120,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'MARKET_TYPE'
            }
          },
          {
            prop: 'constType',
            label: '门店建设类型',
            width: 120,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'CONST_TYPE'
            }
          }
        ]
      },
      typeFilters: [],
      paramsRaw: {},
      selections: []
    }
  },
  computed: {
    otherFilters() {
      return [...this.serachFilters, ...this.typeFilters]
    }
  },
  watch: {
    type: {
      handler(v) {
        this.setOtherFilters(v)
      },
      immediate: true
    },
    serachFilters: {
      handler(v) {
        if (this.activeType !== this.type) return
        this.$nextTick(() => {
          this.$refs.cTableBox.initTableData()
        })
      }
    }
  },
  created() {
  },
  activated() {
    if (this.ready && this.refreshTableData) {
      this.refreshTableData()
    }
  },
  deactivated() {
    this.ready = true
  },
  methods: {
    setTableHeight() {
      this.$refs.cTableBox.refreshTableHeight()
    },
    // 设置过滤条件
    setOtherFilters(v) {
      this.paramsRaw = {}
      switch (v) {
        case 'all':
          this.typeFilters = []
          break
        case 'waitConfirm':
          this.typeFilters = [
            otherFiltersItem('isEnd', '0', '='),
            // 除全部页签，其余全展示正常
            otherFiltersItem('state', 'A', '='),
            otherFiltersItem('steps', 'B2', '=')
          ]
          break
      }
    },
    // 刷新数据
    refreshTableData(v = 'onPage') {
      this.$nextTick(() => {
        this.$refs.cTableBox.initTableData(v)
      })
    },
    selectionChange(v) {
      this.selections = v
    },
    // 详情
    toDetail(row) {
      this.$router.push({ name: 'DecorateDetail', query: { id: row.id, taskCode: row.decorationTaskCode }})
    }
  }
}
</script>
